package com.czy.controller;

import java.util.Date;

import javax.jms.Queue;
import javax.jms.Topic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

//@Component
public class TopicProducer {

	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;
	@Autowired
	private Topic topic;

	@SuppressWarnings("deprecation")
	public void produceMsg() {
		jmsMessagingTemplate.getJmsTemplate().setPubSubDomain(true);//设置主题发送方式
		jmsMessagingTemplate.convertAndSend(topic, "message-topic:" + new Date().toLocaleString());
	}
	
	
//	@SuppressWarnings("deprecation")
//	@Scheduled(fixedDelay = 3000)
//    public void produceMsgScheduled(){
//		jmsMessagingTemplate.getJmsTemplate().setPubSubDomain(true);//设置主题发送方式
//        jmsMessagingTemplate.convertAndSend(topic,"****topic**Scheduled:"+ new Date().toLocaleString());
//        System.out.println("发送消息。。。");
//    }
}
